package com.tjbank.cssys.web.controller;


import com.tjbank.cssys.domain.CkLog;
import com.tjbank.cssys.domain.CkOrderOutboundForm;
import com.tjbank.cssys.web.service.CkLogService;
import com.tjbank.cssys.web.service.CkOrderOutboundFormService;
import com.tjbank.cssys.web.util.CommonResult;
import com.tjbank.cssys.web.util.GetUserCodeFromToken;
import io.swagger.annotations.Api;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@RequestMapping("/outboundForm")
@RestController
@Api(tags = "CkOrderAccountAgeFormController", description = "外呼产能表")
public class CkOrderOutboundFormController {
    @Autowired
    private CkOrderOutboundFormService ckOrderOutboundFormService;
    @Autowired
    private CkLogService ckLogService;
    private static Logger logger = LoggerFactory.getLogger(CkOrderOutboundFormController.class);

    @RequestMapping("/selectAllCkOrderOutboundForm")
    public CommonResult selectAllCkOrderOutboundForm(@RequestParam("dateTime") String dateTime, HttpServletRequest request) {
        List<CkOrderOutboundForm> ckOrderOutboundFormList = ckOrderOutboundFormService.selectAllCkOrderOutboundForm(dateTime);

        String userCode = null;
        try {
            userCode = GetUserCodeFromToken.getUserCode(request);
        } catch (Exception e) {
            logger.error("外呼产能表异常",e.getMessage());
        }
        CkLog ckLog = new CkLog();
        ckLog.setLogId(UUID.randomUUID().toString());
        ckLog.setLogName(UUID.randomUUID().toString());
        Date date = new Date();
        ckLog.setTimes(new Date(date.getTime()));
        ckLog.setUserId(userCode);
        ckLog.setParams("");
        ckLog.setOperationType("获取外呼产能列表");


        if (CollectionUtils.isNotEmpty(ckOrderOutboundFormList)) {
            ckLog.setResult("success:200");
            ckLogService.addInsert(ckLog);
            return CommonResult.success(ckOrderOutboundFormList);
        } else {
            ckLog.setResult("success:200");
            ckLogService.addInsert(ckLog);
            return CommonResult.success(null, "该段时间的数据为空");
        }
    }
}
